package com.tencent.crazypenguin.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/***
 *
 * <p>
 * 配置信息工具类 <br>
 * </p>
 * @author julianxiao <br>
 * @since 1.0.0
 *
 */
public class ConfigUtil {

	private static Properties props = null;

	static{
		InputStream is = ConfigUtil.class.getClassLoader().getResourceAsStream("config.properties");
		if (is == null) {  
	        throw new IllegalArgumentException(  
	                "[config.properties] is not found!");  
    	}  
		props = new Properties();
		try {
			props.load(is);
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}


	private ConfigUtil(){}

	private static class ConfigUtilGet{
		private static final ConfigUtil instance= new ConfigUtil();
	}

	public static ConfigUtil one(){
		return ConfigUtilGet.instance;
	}

	private String getConfig(String key) {
		String value ="" + props.getProperty(key);
		return value.trim();
	}
	
	public String getMasterSecret() {
		return getConfig("masterSecret");
	}

	public String getAppKey() {
		return getConfig("appKey");
	}
	
	// by pluschen
	public static String iGetConfig(String key) {
		String value ="" + props.getProperty(key);
		return value.trim();
	}
	
	public static void main(String[] args){
		System.out.println(iGetConfig("tokenKey"));
	}

}
